package com.tju.backend.plugin.web_socket;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.tju.backend.entity.TProduct;
import org.tio.core.ChannelContext;
import org.tio.core.intf.Packet;
import org.tio.websocket.server.WsServerAioListener;

/**
 * 用户根据情况来完成该类的实现
 *
 * @USER: CLS
 */
public class TioServerAioListener extends WsServerAioListener {

    public static final TioServerAioListener me = new TioServerAioListener();

    private TioServerAioListener() {

    }

    public static void main(String[] args) {

        String name ="{\"productName\":\"茶花脸盘\",\"productCoding\":\"214591\",\"productSpecification\":\"6只\",\"productBrand\":\"茶花\",\"productColour\":\"灰色\",\"productTexture\":\"塑料\"}";
        TProduct p = JSON.parseObject(name,TProduct.class);
        System.err.println(p);
    }

    @Override
    public void onAfterConnected(ChannelContext channelContext, boolean isConnected, boolean isReconnect) throws Exception {
        super.onAfterConnected(channelContext, isConnected, isReconnect);
    }

    @Override
    public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {
        super.onAfterSent(channelContext, packet, isSentSuccess);
    }

    /**
     * 客户断开处理方法
     *
     * @param channelContext
     * @param throwable
     * @param remark
     * @param isRemove
     * @throws Exception
     */
    @Override
    public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) throws Exception {
        super.onBeforeClose(channelContext, throwable, remark, isRemove);
    }

    @Override
    public void onAfterDecoded(ChannelContext channelContext, Packet packet, int packetSize) throws Exception {
        super.onAfterDecoded(channelContext, packet, packetSize);
    }

    @Override
    public void onAfterReceivedBytes(ChannelContext channelContext, int receivedBytes) throws Exception {
        super.onAfterReceivedBytes(channelContext, receivedBytes);
    }

    @Override
    public void onAfterHandled(ChannelContext channelContext, Packet packet, long cost) throws Exception {
        super.onAfterHandled(channelContext, packet, cost);
    }

}
